<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('设备信息修改')"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">id</label>
                    <div class="layui-input-block">
                        <input type="text" th:value="${device.id}" name="id">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">设备名</label>
                    <div class="layui-input-block">
                        <input type="text" th:value="${device.deviceName}" name="deviceName" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">制造公司</label>
                    <div class="layui-input-block">
                        <input class="layui-input" th:field="${device.deviceCompany}" name="deviceCompany"
                               lay-verify="required" autocomplete="off"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">单价</label>
                    <div class="layui-input-block">
                        <input class="layui-input" th:field="${device.devicePrice}"
                               oninput="this.value=this.value.toString().match(/^\d+(?:\.\d{0,2})?/)" name="devicePrice"
                               lay-verify="required" autocomplete="off"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">设备分类</label>
                    <div class="layui-input-block">
                        <select th:field="${device.sort}" th:value="${device.sort}" name="sort" lay-verify="required">
                            <option value="">请选择设备分类</option>
                            <option th:selected="${device.sort == '0'}" value="0">办公类设备</option>
                            <option th:selected="${device.sort == '1'}" value="1">科研类设备</option>
                            <option th:selected="${device.sort == '2'}" value="2">其他设备</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea" rows="5" th:field="${device.remark}" name="remark"
                                  lay-verify="required" maxlength="500" autocomplete="off"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">是否维修</label>
                    <div class="layui-input-block">
                        <input type="radio" name="repair" th:checked="${device.repair eq '0'}" value="0"
                               title="设备正常">
                        <input type="radio" name="repair" th:checked="${device.repair eq '1'}" value="1" title="维修中">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">是否报废</label>
                    <div class="layui-input-block">
                        <input type="radio" name="scrap" th:checked="${device.scrap eq '0'}" value="0" title="设备正常">
                        <input type="radio" name="scrap" th:checked="${device.scrap eq '1'}" value="1" title="已报废">
                    </div>
                </div>

            </div>
        </div>
    </div>

    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        form.on('submit(user-update)', function (data) {
            $.ajax({
                url: '/device/update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>